package com.opgea.crm.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.opgea.crm.domain.entities.LeadDocuments;

@Repository
public class LeadDocumentsRepoImpl implements LeadDocumentsRepo {

	@PersistenceContext
	EntityManager em;
	
	
	public void create(LeadDocuments doc) {
		em.persist(doc);
	}

	
	public LeadDocuments find(long id) {
		return em.find(LeadDocuments.class, id);
	}

	
	public List<LeadDocuments> findAll() {
		String query = "SELECT d LeadDocuments FROM d ";
		return em.createQuery(query, LeadDocuments.class).getResultList();
	}

	
	public List<LeadDocuments> findAllByLead(long leadId) {
		System.out.println("Document Impl : "+leadId);
		String query = "SELECT d FROM LeadDocuments d WHERE d.lead.id = "+leadId;
		List<LeadDocuments> docList = em.createQuery(query, LeadDocuments.class).getResultList();
		//System.out.println(docList.get(0));
		return docList;
	}

}
